const XLSX = require('xlsx');
const path = require("node:path");
const fs = require("node:fs");


const content = [
    ['ID', 'Name', 'DOB'],
    [1, 'John Doe', new Date(1990, 1, 1)], // 注意月份是从0开始的，所以1月是0，2月是1，以此类推
    [2, 'Jane Doe', new Date(1991, 2, 2)]
];
const filePath = path.join(__dirname, "test.xlsx");

function output(content, filePath) {
    const worksheet = XLSX.utils.aoa_to_sheet(content);

    const workbook = XLSX.utils.book_new();

    XLSX.utils.book_append_sheet(workbook,worksheet,'company info');
    const dir = path.dirname(filePath);
    if (!fs.existsSync(dir)) {
        fs.mkdirSync(dir, { recursive: true });
    }

    XLSX.writeFile(workbook, filePath);
    console.log("文件已保存!");

}

output(content,filePath);